from abc import ABC, abstractmethod


# 定义抽象类,通过继承ABC来定义抽象类
class Animal(ABC):

    def __init__(self, name):
        self.name = name

    # 定义抽象方法
    @abstractmethod
    def speak(self):
        pass

    def sound():
        print("动物发出声音")


class Dog(Animal):

    def __init__(self, name):
        super().__init__(name)
        self.name = name

    def speak(self):
        print("dog,汪汪叫。。。。")


class Cat(Animal):

    def __init__(self, name):
        super().__init__(name)
        self.name = name

    def speak(self):
        print("cat,汪汪叫。。。。")


dog = Dog("husky")
dog.speak()

cat = Dog("jimi")
cat.speak()

## 不能实例化抽象类，会报错 TypeError: Can't instantiate abstract class Animal without an implementation for abstract method 'speak'
animal = Animal("all")
animal.speak()
